home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / CENVIW2.ZIP / WINUTIL.LIB < prev   
Text File  |  1993-09-13  |  5KB  |  129 lines

  1. // WinUtil.lib - Cmm code wrapper for various useful Windows functions.
  2. //               This is by no means an exhaustive collection, but simply
  3. //               examples.  You may #include this file in your CMM source
  4. //               or you may simply copy the routines you like into your
  5. //               code.  The routines in this file are:
  6. // GetSystemMetrics() - Width and height of various display elements
  7. // GetWindowRect() - return structure containing window coordinates
  8. // MoveWindow() - Move a window to specified coordinates on the screen
  9. // GetWindowHandle() - get handle for a window based on it's matching title
  10. // GetWindowText() - Get title of a window
  11.  
  12. GetSystemMetrics(Index)
  13.    // return this system metric
  14. {
  15.    #define SM_CXSCREEN         0    // screen width
  16.    #define SM_CYSCREEN         1    // screen height
  17.    #define SM_CXVSCROLL        2
  18.    #define SM_CYHSCROLL        3
  19.    #define SM_CYCAPTION        4
  20.    #define SM_CXBORDER         5
  21.    #define SM_CYBORDER         6
  22.    #define SM_CXDLGFRAME       7
  23.    #define SM_CYDLGFRAME       8
  24.    #define SM_CYVTHUMB         9
  25.    #define SM_CXHTHUMB         10
  26.    #define SM_CXICON           11
  27.    #define SM_CYICON           12
  28.    #define SM_CXCURSOR         13
  29.    #define SM_CYCURSOR         14
  30.    #define SM_CYMENU           15
  31.    #define SM_CXFULLSCREEN     16
  32.    #define SM_CYFULLSCREEN     17
  33.    #define SM_CYKANJIWINDOW    18
  34.    #define SM_MOUSEPRESENT     19
  35.    #define SM_CYVSCROLL        20
  36.    #define SM_CXHSCROLL        21
  37.    #define SM_DEBUG            22
  38.    #define SM_SWAPBUTTON       23
  39.    #define SM_RESERVED1        24
  40.    #define SM_RESERVED2        25
  41.    #define SM_RESERVED3        26
  42.    #define SM_RESERVED4        27
  43.    #define SM_CXMIN            28
  44.    #define SM_CYMIN            29
  45.    #define SM_CXSIZE           30
  46.    #define SM_CYSIZE           31
  47.    #define SM_CXFRAME          32
  48.    #define SM_CYFRAME          33
  49.    #define SM_CXMINTRACK       34
  50.    #define SM_CYMINTRACK       35
  51.    #define SM_CMETRICS         36
  52.    return( DynamicLink("USER","GETSYSTEMMETRICS",SWORD16,PASCAL,Index) );
  53. }
  54.  
  55. GetWindowRect(WindowHandle)
  56.    // return window coordinates in a structure with the following members
  57.    //   .left
  58.    //   .top
  59.    //   .right
  60.    //   .bottom
  61. {
  62.    // set up blob to retrieve four integers
  63.    BLObSize(_rect,4 * 2/*integer size*/);
  64.    DynamicLink("USER","GETWINDOWRECT",SWORD16,PASCAL,WindowHandle,_rect);
  65.    _ret.left = BLObGet(_rect,0,SWORD16);
  66.    _ret.top = BLObGet(_rect,2,SWORD16);
  67.    _ret.right = BLObGet(_rect,4,SWORD16);
  68.    _ret.bottom = BLObGet(_rect,6,SWORD16);
  69.    return(_ret);
  70. }
  71.  
  72. GetClientRect(WindowHandle)
  73.    // return window client-area coordinates in a structure with the following members
  74.    //   .left
  75.    //   .top
  76.    //   .right
  77.    //   .bottom
  78. {
  79.    // set up blob to retrieve four integers
  80.    BLObSize(_rect,4 * 2/*integer size*/);
  81.    DynamicLink("USER","GETCLIENTRECT",SWORD16,PASCAL,WindowHandle,_rect);
  82.    _ret.left = BLObGet(_rect,0,SWORD16);
  83.    _ret.top = BLObGet(_rect,2,SWORD16);
  84.    _ret.right = BLObGet(_rect,4,SWORD16);
  85.    _ret.bottom = BLObGet(_rect,6,SWORD16);
  86.    return(_ret);
  87. }
  88.  
  89.  
  90. MoveWindow(WindowHandle,x,y,width,height,Repaint)
  91.    // move the window to coordinates x,y on the screen, with size width,height.
  92.    // if Repaint is not-False then will repaint window
  93. {
  94.    DynamicLink("USER","MOVEWINDOW",SWORD16,PASCAL,
  95.                WindowHandle,x,y,width,height,Repaint);
  96. }
  97.  
  98. GetWindowText(WindowHandle)
  99.    // return string containing text of this Window handle, or NULL if this window
  100.    // has no text
  101. {
  102.    BLObSize(_buf,200);
  103.    if ( 0 == DynamicLink("USER","GETWINDOWTEXT",SWORD16,PASCAL,
  104.                          WindowHandle,_buf,BLObSize(_buf)-1) ) {
  105.       return(NULL);
  106.    }
  107.    // copy to shorter string and return that
  108.    strcpy(_ret,_buf);
  109.    return(_ret);
  110. }
  111.  
  112. GetWindowHandle(Title)
  113.    // Search for a window to match the string: Title or match title for at
  114.    // least the length of the string. Return the handle of the window as an
  115.    // integer, or return 0 if the window was not found.
  116. {
  117.    _len = strlen(Title);
  118.    if ( NULL == (_winList = WindowList()) ) return 0;
  119.    _count = 1 + GetArraySpan(_winList);
  120.    for ( i = 0; i < _count; i++ ) {
  121.       // compare the title for this window, if it has one
  122.       if ( NULL != (_title = GetWindowText(_winList[i]))
  123.         && 0 == strnicmp(Title,_title,_len) )
  124.          return(_winList[i]);
  125.    }
  126.    return(0);
  127. }
  128.  
  129.